#pragma once

#include "topdbs_base_connection.hpp"
#include "odbc_common.hpp"

namespace topdbs
{
	class odbc_connection 
		: public topdbs_base_connection
	{
	private:
		HENV  m_henv;
		HDBC  m_hdbc;
		bool  m_isTransaction;
        bool  m_isConnected;
		string m_user;
		string m_pass;
		string m_dbname;
	public:
		odbc_connection();
		virtual ~odbc_connection();

        inline HENV henv() { return m_henv; };

		//! Opens the connection to a data source.
		virtual int  connect(
			eDBSClient_t dbsClientType,
			const string& dbString,
			const string& user=string(),
			const string& pass=string(),
			void* pOption = NULL ) override;
		//! Returns the connection state for a particular connection object.	
		virtual bool isConnected() override;
		virtual int  reConnect() override;
		//! Disconnects the connection from the database.
		virtual int  disConnect() override;
		//! Begin transactions.
		virtual int  begin() override;
		//! Commits transactions.
		virtual int  commit() override;
		//! Rollback transactions.
		virtual int  rollback() override;
		//! Returns transactions.
		virtual bool isTransaction() override;
		//! Sets the connection to be committed automatically.
		virtual int  autoCommit(bool on = true) override;
		//! Returns the native connection
		virtual void*  getConnection() override;
		//! Returns the current this
		virtual void* from_this() override;
        //! Sets the connection lock wait time
		virtual int   lockwait() override;
    private:
        int connect();    
		int execute(const std::string& sSQL);
	}; 

}